package com.site.wisdom_construction.controller.safetyModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.safetyModule.SafetyRiskSourcePublicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/12
 * @Description
 */
@Api(tags = "公共风险源信息接口")
@RestController
@RequestMapping("SafetyRiskSourcePublic")
@CrossOrigin
public class SafetyRiskSourcePublicController {
    @Autowired
    private SafetyRiskSourcePublicService safetyRiskSourcePublicService;

    @ApiOperation(value = "增加公共风险源信息", notes = "测试数据:")
    @PostMapping("/insertSafetyRiskSourcePublic")
    public JsonResult insertSafetyRiskSourcePublic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = safetyRiskSourcePublicService.insertSafetyRiskSourcePublic(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入公共风险源信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入公共风险源信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除公共风险源信息", notes = "测试数据:")
    @PostMapping("/deleteSafetyRiskSourcePublic")
    public JsonResult deleteSafetyRiskSourcePublic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = safetyRiskSourcePublicService.deleteSafetyRiskSourcePublic(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除公共风险源信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除公共风险源信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改公共风险源信息", notes = "测试数据:")
    @PostMapping("/updateSafetyRiskSourcePublic")
    public JsonResult updateSafetyRiskSourcePublic(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = safetyRiskSourcePublicService.updateSafetyRiskSourcePublic(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改公共风险源信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改公共风险源信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询公共风险源信息", notes = "测试数据:")
    @PostMapping("/findSafetyRiskSourcePublicByPage")
    public Page findSafetyRiskSourcePublicByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(safetyRiskSourcePublicService.Total(map));
        page.setItems(safetyRiskSourcePublicService.findSafetyRiskSourcePublicByPage(map));
        return page;
    }

    @ApiOperation(value = "查询全部公共风险源信息", notes = "测试数据:")
    @PostMapping("/selectSafetyRiskSourcePublic")
    public OneDataResult selectSafetyRiskSourcePublic(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(safetyRiskSourcePublicService.selectSafetyRiskSourcePublic(map));
        return oneDataResult;
    }

    @ApiOperation(value = "根据ID查询公共风险源信息", notes = "测试数据:")
    @PostMapping("/findSafetyRiskSourcePublicById")
    public OneDataResult findSafetyRiskSourcePublicById(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(safetyRiskSourcePublicService.findSafetyRiskSourcePublicById(map));
        return oneDataResult;
    }
}
